package facade;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import dao.AssertionDAO;
import dao.SoapuiProjectDAO;
import dao.TestSuiteDAO;
import entity.Assertion;
import entity.Configuration;
import entity.SoapuiProject;
import entity.TestSuite;

public class SoapuiProjectFacade implements Serializable{

	private static final long serialVersionUID = 1L;

	SoapuiProjectDAO projectDAO = new SoapuiProjectDAO();
	TestSuiteDAO testSuiteDAO = new TestSuiteDAO();
	AssertionDAO assertionDAO = new AssertionDAO();
	
	public void createSoapuiProject(SoapuiProject project, TestSuite testSuite, Configuration configuration){
		projectDAO.beginTransaction();
		projectDAO.save(project);
		projectDAO.commitAndCloseTransaction();
		testSuiteDAO.beginTransaction();
		testSuite.setProject(project);
		Assertion assertion = new Assertion();
		assertion.setRestRequest(project.getTestSuite().getTestCase().getTestStep().getConfig().getRestRequest());
		assertion.setConfiguration(configuration);
		testSuite.getTestCase().getTestStep().getConfig().getRestRequest().getAssertion().add(assertion);
		testSuiteDAO.update(testSuite);
		testSuiteDAO.commitAndCloseTransaction();
	}

	public List<TestSuite> getListTableBuild() {
		testSuiteDAO.beginTransaction();
		List<TestSuite> suites = testSuiteDAO.findAll();
		testSuiteDAO.closeTransaction();
		return suites;
	}
	
	public List<SoapuiProject> getListSoapuiProjects() {
		projectDAO.beginTransaction();
		List<SoapuiProject> projects = new ArrayList<SoapuiProject>();
		projects = projectDAO.findAll();
		return projects;
	}

	public List<SoapuiProject> getProjectsByName(String nameProject) {
		projectDAO.beginTransaction();
		List<SoapuiProject>  projects = projectDAO.getProjectsByName(nameProject);
		return projects;
	}
	
	public List<TestSuite> getProjectsByNameTestSuite(String nameProject) {
		testSuiteDAO.beginTransaction();
		List<TestSuite>  Tsuites = testSuiteDAO.getProjectsByName(nameProject);
		return Tsuites;
	}
	
	public List<Assertion> getAssertionsbyId(Integer id){
		assertionDAO.beginTransaction();
		List<Assertion> assertions = assertionDAO.getAssertionById(id);
		return assertions;
	}
	
}
